#!/usr/bin/env python
import pygtk
pygtk.require('2.0')
import gtk

class EventWindow:
    def __init__(self):
        self.last_x = self.last_y = -1000
        #self.mlx = self.mly = -1000
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.set_title("Tablet Event Visualization")
        self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
        self.window.connect("destroy", lambda w: gtk.main_quit())
        self.area = gtk.DrawingArea()
        self.area.set_size_request(1200, 800)
        self.window.add(self.area)
        self.area.set_events(gtk.gdk.POINTER_MOTION_MASK )
        self.area.set_extension_events(gtk.gdk.EXTENSION_EVENTS_ALL)
        self.area.connect("motion-notify-event", self.motion_notify)
        self.area.connect("motion_notify_event", self.motion_notify)
        self.area.show()
        self.window.show()
        self.style = self.area.get_style()
        self.gc = self.style.fg_gc[gtk.STATE_NORMAL]
        return
        
    #def is_pen_event(self, event):
    #    if (event.device.name[:9] == "Wacom Pen") | \
    #       (event.device.name[:2] == "PT"):
    #    #        print event.type, event.device.name, event.device.source
    #            return True
    #    return False
    
    def motion_notify(self, area, event):    
        #print event.device.name + ':', event.x_root, event.y_root
        #if self.is_pen_event(event):
        self.gc.set_rgb_fg_color(gtk.gdk.Color(0,0,0))
        self.area.window.draw_line(self.gc,
                                    int(self.last_x),
                                    int(self.last_y),
                                    int(event.x_root),
                                    int(event.y_root))
        self.last_x, self.last_y = event.x_root, event.y_root
        self.last_event = event.get_time()
        #else:
        #    self.gc.set_rgb_fg_color(gtk.gdk.Color(0,0,65535))
        #    self.area.window.draw_line(self.gc,
        #                                int(self.mlx) / 2 + 600,
        #                                int(self.mly ),
        #                                int(event.x_root) / 2 + 600,
        #                                int(event.y_root))
        #    self.mlx, self.mly = event.x_root, event.y_root
        #    self.last_event = event.get_time()
        return True

if __name__ == "__main__":
    win = EventWindow()
    gtk.main()
 
